/**
 * Timer class implementing the timeout for system. The timer is
 * checked at a rate specified in the DS class
 */
public class Timer extends Thread {
    private int timeout;
    private boolean done = false;

    public Timer(int timeout) {
        this.timeout = timeout;
    }

    // Method where Timer waits when done
    private synchronized void waiting() throws InterruptedException {
        wait();
    }

    // Method for checking if timeout is reached
    public synchronized boolean checktimer() {
        if(done){
            notify(); // notify to kill timer
            return true;
        }
        return false;
    }

    private void runtimer() {
        try {
            sleep(timeout);
            done = true;

        }
        catch (Exception e) {

        }
    }

    @Override
    public void run() {
        runtimer();
    }
}